<?php

namespace IDock\Insurance\LIHI\Response;

use IDock\Http\Response;
use IDock\Insurance\LIHI\Response\AllLIHIResponse;

class LIHITokenResponse extends AllLIHIResponse
{
    protected $token = '';

    protected $tokenExpire = '';

    public function resolve(): Response
    {
        $body = $this->getBody();
        if (!json_decode($body)) {
            $this->setError('返回数据异常');
            return  $this;
        }
        $data = json_decode($body,true);

        if ($this->printer and  is_string($this->printer)) {
            $this->printer = new $this->printer;
        }

        $this->setBody($data);

        return $this;
    }

    public function printerInit(): Response
    {
        return $this;
    }

    public function getToken(): string
    {
        return $this->token;
    }

    public function getTokenExpire(): string
    {
        return $this->tokenExpire;
    }
}
